//将本地图片地址转换为base64

const urlBase64 = {
	setBase64(url, name,type) {
		if(type == 1){
			uni.downloadFile({
				url: url, //仅为示例，并非真实的资源
				success: (res) => {
					if (res.statusCode === 200) {
						uni.getFileSystemManager().saveFile({
							tempFilePath: res.tempFilePath,
							success: function(red) {
								uni.setStorageSync(name, red.savedFilePath);
							},
						});
					} else {
						uni.setStorageSync(name, '');
					}
				},fail: (err) => {
					uni.setStorageSync(name, '');
					console.log('downloadFile fail, err is:', err);
				}
			});
		}else if(type == 2){
			let arrList = [];
			url.forEach((item)=>{
				uni.downloadFile({
					url: item, //仅为示例，并非真实的资源
					success: (res) => {
						if (res.statusCode === 200) {
							uni.getFileSystemManager().saveFile({
								tempFilePath: res.tempFilePath,
								success: function(red) {
									arrList.push(red.savedFilePath);
									if(arrList.length == url.length){
										uni.setStorageSync(name, arrList);
									}
								},
							});
						} else {
							uni.setStorageSync(name, '');
						}
					},fail: (err) => {
						uni.setStorageSync(name, '');
						console.log('downloadFile fail, err is:', err);
					}
				});
			})		
		}
		
	}
}



export default urlBase64;